package com.guizi.halftimesroom.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.guizi.halftimesroom.R;
import com.guizi.halftimesroom.bean.RecommandListNormanlBean;
import com.guizi.halftimesroom.bean.RecommandListSpecialBean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Alan on 2016/7/20.
 */
public class DIscoverBottomView extends LinearLayout {
    private Context mContext;
    private LinearLayout ll_selected;
    private ImageView iv_discover_special;
    private TextView tv_discover_special_title,tv_discover_special_discribe,tv_discover_special_discribe2;
    private int count;

    public DIscoverBottomView(Context context) {
        this(context,null);
    }

    public DIscoverBottomView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public DIscoverBottomView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context context) {
        this.mContext =context;
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_discover_recommand_bottom, this);
        ll_selected = (LinearLayout) view.findViewById(R.id.ll_selected);
        iv_discover_special= (ImageView) view.findViewById(R.id.iv_discover_special);
        tv_discover_special_title= (TextView) view.findViewById(R.id.tv_discover_special_title);
        tv_discover_special_discribe= (TextView) view.findViewById(R.id.tv_discover_special_discribe);
        tv_discover_special_discribe2= (TextView) view.findViewById(R.id.tv_discover_special_discribe2);
    }
    public void setData(List<RecommandListNormanlBean> list, RecommandListSpecialBean specialBean){
        setNormanl(list);
        setSpecial(specialBean);
    }


    private void setNormanl(List<RecommandListNormanlBean> list) {
        count=list.size()/2;
        for (int i = 0; i <count ; i++) {
            selectedNormalView normalView = new selectedNormalView(mContext);
            normalView.setData(list.get(i*2),list.get((i*2+1)));
            ll_selected.addView(normalView);
        }
    }
    private void setSpecial(RecommandListSpecialBean specialBean) {
        Picasso.with(mContext).load(specialBean.getData().get(0).getCover()).into(iv_discover_special);
        tv_discover_special_title.setText(specialBean.getData().get(0).getLabels().get(0));
        tv_discover_special_discribe.setText(specialBean.getData().get(0).getTitle());
        tv_discover_special_discribe2.setText(specialBean.getData().get(0).getIntro());
    }
}
